package de.koller.transit.engine.brush;

import de.koller.aframe.util.misc.ABoundingBox;
import de.koller.aframe.util.misc.AColor;
import de.koller.aframe.util.misc.ADirection2D;
import de.koller.aframe.util.misc.AStat;
import de.koller.aframe.util.misc.SwapValue;
import de.koller.oceanFramework.math.RVec2;
import de.koller.transit.TransitStart;

public class Brush {
	
	public final SwapValue<RVec2> position = new SwapValue<>();
	public final AStat velocity = new AStat();
	public final AStat turnVelocity = new AStat();
	public final ADirection2D direction = new ADirection2D();
	public final AStat size = new AStat();
	
	public final AColor color = new AColor();

	public void updateThis( int elapsedTime ) {
		RVec2 v = direction.createVec( (float)( velocity.getValue() * (elapsedTime * 0.001) ) );
		
		RVec2 np = position.getCurrent().newInstace().add( v );
		if( np.x + size.getValue() > TransitStart.WIDTH || np.x - size.getValue() < 0 )
			v.x = 0;
		if( np.y + size.getValue() > TransitStart.HEIGHT || np.y - size.getValue() < 0 )
			v.y = 0;
		
		position.push( position.getCurrent().newInstace().add( v ) );
	}
	
	public ABoundingBox getClip() {
		float minx = Math.min( position.getCurrent().x, position.getPrevious().x );
		float miny = Math.min( position.getCurrent().y, position.getPrevious().y );
		float maxx = Math.max( position.getCurrent().x, position.getPrevious().x );
		float maxy = Math.max( position.getCurrent().y, position.getPrevious().y );
		
		minx -= size.getValue() + 5 + 35;
		miny -= size.getValue() + 5 + 60;
		maxx += size.getValue() + 5 + 40;
		maxy += size.getValue() + 5;
		
		return new ABoundingBox( minx, miny, maxx - minx, maxy - miny );
	}
}
